<?php
/**
 * Created by PhpStorm.
 * User: Liulibao
 * Date: 2019/9/18
 * Time: 10:10
 */

namespace app\home\controller;


use app\common\model\Goods;
use think\Lang;
use think\Log;

load_trait('controller/Jump');

class Sellergoodsinfomessage extends BaseSeller
{
    var $_store_id;

    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'home/lang/' . config('default_lang') . '/sellergoodsadd.lang.php');
        $this->template_dir = 'default/seller/sellergoodsinfomessage/';
    }


    /**
     * 在售商品列表
     */

    public function index()
    {

        $goods_model = new Goods();
        $where = array();
        $where['store_id'] = session('store_id');
        $where['goods_status'] = array('in', '1,3');
        $gc_id = intval(input('get.gc_id'));
        if ($gc_id != '') {
            $where["gc_id|gc_id_1|gc_id_2|gc_id_3"] = $gc_id;
        }
        $b_id = intval(input('get.b_id'));
        if ($b_id != '') {
            $where['brand_id'] = intval($b_id);
        }

        $keyword = trim(input('get.keyword'));
        $search_type = trim(input('get.search_type'));

        if (trim($keyword) != '') {
            switch ($search_type) {
                case 0:
                    $where['goods_name'] = array('like', '%' . trim($keyword) . '%');
                    break;
                case 2:
                    $where['goods_commonid'] = intval($keyword);
                    break;
            }
        }

        $goods_list = $goods_model->g_getGoodsCommonList($where);
        //获取分类名称
        $goods_lists = getClassName($goods_list);
        $this->assign('status', array('1' => '上架', '3' => '下架'));
        $this->assign('verify', array('1' => '通过', '3' => '通过'));
        $this->assign('show_page', $goods_model->page_info->render());
        $this->assign('goods_list', $goods_lists);


        $goodsclass_model = model('goodsclass');
        //父类列表，只取到第二级
        $parent_list = $goodsclass_model->getTreeClassList(2);
        $gc_list = array();
        if (is_array($parent_list)) {
            foreach ($parent_list as $k => $v) {
                $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
                if ($v['deep'] == 1)
                    $gc_list[$k] = $v;
            }
        }
        $this->assign('gc_list', $gc_list);
        //分类
        $goods_class = model('goodsclass')->getGoodsclassLineForTag('91');
        $this->assign('goods_class', $goods_class);
        //品牌
        $typeinfo = model('type')->getAttribute('1', session('store_id'), '91');
        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
        $this->assign('brand_list', $brand_list);

        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('goods_list');

        return $this->fetch($this->template_dir . 'index');
    }

    /**
     * 待审核商品列表
     */
    public function goods_verify_list()
    {
        #获取符合条件商品id

        $where = array();
        $where['goods_status'] = 0; #状态
        $where['store_id'] = $_SESSION['home']['store_id'];

        $goods_model = model('goods');
        $b_id = intval(input('get.b_id'));
        if ($b_id != '') {
            $where['brand_id'] = intval($b_id);
        }
        $gc_id = intval(input('get.gc_id'));
        if ($gc_id != '') {
            $where["gc_id|gc_id_1|gc_id_2|gc_id_3"] = $gc_id;
        }

        $keyword = trim(input('get.keyword'));
        $search_type = trim(input('get.search_type'));
        if (trim($keyword) != '') {
            switch ($search_type) {
                case 0:
                    $where['goods_name'] = array('like', '%' . trim($keyword) . '%');
                    break;
                case 1:
                    $where['goods_serial'] = array('like', '%' . trim($keyword) . '%');
                    break;
                case 2:
                    $where['goods_commonid'] = intval($keyword);
                    break;
            }
        }

        $goods_list = $goods_model->g_getGoodsCommonList($where);
        //p($where);die;
        $this->assign('show_page', $goods_model->page_info->render());


        $this->assign('goods_list', $goods_list);
        // 计算库存
        $storage_array = $goods_model->calculateStorage($goods_list);
        $this->assign('storage_array', $storage_array);

        // 商品分类
        $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
        $this->assign('store_goods_class', $store_goods_class);

        $goods_class = model('goodsclass')->getGoodsclassLineForTag('91');
        $this->assign('goods_class', $goods_class);
        $goodsclass_model = model('goodsclass');
        //父类列表，只取到第二级
        $parent_list = $goodsclass_model->getTreeClassList(2);
        $gc_list = array();
        if (is_array($parent_list)) {
            foreach ($parent_list as $k => $v) {
                $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
                if ($v['deep'] == 1)
                    $gc_list[$k] = $v;
            }
        }
        $this->assign('gc_list', $gc_list);

        //品牌
        $typeinfo = model('type')->getAttribute('1', session('store_id'), '91');
        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
        $this->assign('brand_list', $brand_list);

        $this->assign('verify', array('0' => '待审核'));

        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('goods_verify_list');
        echo $this->fetch($this->template_dir . 'goods_verify_list');
        exit;
    }


    /**
     * 审核失败商品列表
     */
    public function goods_off_list()
    {
        #获取符合条件的商品id 
        $where = array();
        $where['store_id'] = session('store_id');
        $where['goods_status'] = 2;
        $goods_model = model('goods');
        $b_id = intval(input('get.b_id'));
        if ($b_id != '') {
            $where['brand_id'] = intval($b_id);
        }
        $gc_id = intval(input('get.gc_id'));
        if ($gc_id != '') {
            $where["gc_id|gc_id_1|gc_id_2|gc_id_3"] = $gc_id;
        }

        $keyword = trim(input('get.keyword'));
        $search_type = trim(input('get.search_type'));
        if (trim($keyword) != '') {
            switch ($search_type) {
                case 0:
                    $where['goods_name'] = array('like', '%' . trim($keyword) . '%');
                    break;
                case 2:
                    $where['goods_commonid'] = intval($keyword);
                    break;
            }
        }

        $goods_list = $goods_model->g_getGoodsCommonList($where);

        $this->assign('show_page', $goods_model->page_info->render());
        $this->assign('goods_list', $goods_list);
        // 计算库存
        $storage_array = $goods_model->calculateStorage($goods_list);
        $this->assign('storage_array', $storage_array);
        // 商品分类
        $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
        $this->assign('store_goods_class', $store_goods_class);

        $goods_class = model('goodsclass')->getGoodsclassLineForTag('91');
        $this->assign('goods_class', $goods_class);
        $goodsclass_model = model('goodsclass');
        //父类列表，只取到第二级
        $parent_list = $goodsclass_model->getTreeClassList(2);
        $gc_list = array();
        if (is_array($parent_list)) {
            foreach ($parent_list as $k => $v) {
                $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
                if ($v['deep'] == 1)
                    $gc_list[$k] = $v;
            }
        }
        $this->assign('gc_list', $gc_list);

        //品牌
        $typeinfo = model('type')->getAttribute('1', session('store_id'), '91');
        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
        $this->assign('brand_list', $brand_list);

        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('goods_off_list');
        echo $this->fetch($this->template_dir . 'goods_off_list');
        exit;
    }


    /**
     * AJAX添加商品规格值
     */
    public function ajax_add_spec()
    {
        $name = trim(input('get.name'));
        $gc_id = intval(input('get.gc_id'));
        $sp_id = intval(input('get.sp_id'));
        if ($name == '' || $gc_id <= 0 || $sp_id <= 0) {
            echo json_encode(array('done' => false));
            die();
        }
        $insert = array(
            'spvalue_name' => $name, 'sp_id' => $sp_id, 'gc_id' => $gc_id, 'store_id' => session('store_id'),
            'spvalue_color' => null, 'spvalue_sort' => 0,
        );
        $value_id = model('spec')->addSpecvalue($insert);
        if ($value_id) {
            echo json_encode(array('done' => true, 'value_id' => $value_id));
            die();
        } else {
            echo json_encode(array('done' => false));
            die();
        }
    }

    public function save_choose_eare()
    {
        $goods_model = model('goods');
        $type_model = model('type');
        $common_id = input('param.goods_id');
        $update_goods_repair_data = [];
        $update_goods_repair_data['return_goods'] = input('return_goods');
        $update_goods_repair_data['change_goods'] = input('change_goods');
        $update_goods_repair_data['goods_status'] = 4;

        $update_goods_repair_data['area'] = implode(',', $_POST['limits']);


        $update_goodscommon_data = [];
        $update_goodscommon_data['goods_marketprice'] = input('param.goods_marketprice');
        $update_goodscommon_data['goods_price'] = input('param.goods_price');
        $update_goodscommon_data['goods_storage_alarm'] = input('param.goods_storage_alarm');


        if (!empty(input('post.spec/a'))) {
            #先删除原有的 更新goods表数据 然后更新common 和 goods_repair
            db('goods')->where(['goods_commonid' => $common_id])->delete();

            $common_array = db('goodscommon')->where(['goods_commonid' => $common_id])->find();

            // 生成的商品id（SKU）
            $goodsid_array = array();
            // 商品规格
            $spec_array = input('post.spec/a');#获取数组
            if (is_array($spec_array) && !empty($spec_array)) {
                foreach ($spec_array as $value) {
                    $goods = array();
                    $goods['goods_commonid'] = $common_id;
                    $goods['goods_name'] = $common_array['goods_name'] . ' ' . implode(' ', $value['sp_value']);
                    /* $goods['goods_advword'] = $common_array['goods_advword'];*/
                    $goods['spec_values'] = implode(',', $value['sp_value']);
                    $goods['store_id'] = $common_array['store_id'];
                    $goods['store_name'] = session('store_name');
                    $goods['gc_id'] = $common_array['gc_id'];
                    $goods['gc_id_1'] = $common_array['gc_id_1'];
                    $goods['gc_id_2'] = $common_array['gc_id_2'];
                    $goods['gc_id_3'] = $common_array['gc_id_3'];
                    $goods['brand_id'] = $common_array['brand_id'];
                    $goods['goods_price'] = $value['price'];
                    $goods['goods_promotion_price'] = $value['price'];
                    $goods['goods_marketprice'] = $value['marketprice'] == 0 ? $common_array['goods_marketprice'] : $value['marketprice'];
                    $goods['goods_serial'] = $value['sku'];
                    $goods['goods_storage_alarm'] = intval($value['alarm']);
                    $goods['goods_spec'] = serialize($value['sp_value']);
                    $goods['goods_storage'] = $value['stock'];
                    $goods['goods_image'] = $common_array['goods_image'];
                    $goods['goods_state'] = $common_array['goods_state'];
                    $goods['goods_verify'] = $common_array['goods_verify'];
                    $goods['goods_addtime'] = TIMESTAMP;
                    $goods['goods_edittime'] = TIMESTAMP;
                    $goods['areaid_1'] = $common_array['areaid_1'];
                    $goods['areaid_2'] = $common_array['areaid_2'];
                    $goods['color_id'] = isset($value['color']) ? intval($value['color']) : '';
                    $goods['transport_id'] = $common_array['transport_id'];
                    $goods['goods_freight'] = $common_array['goods_freight'];
                    $goods['goods_vat'] = $common_array['goods_vat'];
                    $goods['goods_commend'] = $common_array['goods_commend'];
                    $goods['goods_stcids'] = $common_array['goods_stcids'];
                    $goods['is_virtual'] = $common_array['is_virtual'];
                    $goods['virtual_indate'] = $common_array['virtual_indate'];
                    $goods['virtual_limit'] = $common_array['virtual_limit'];
                    $goods['virtual_invalid_refund'] = $common_array['virtual_invalid_refund'];
                    $goods['is_goodsfcode'] = $common_array['is_goodsfcode'];
                    $goods['is_appoint'] = $common_array['is_appoint'];
                    $goods['is_presell'] = $common_array['is_presell'];
                    $goods['is_platform_store'] = $common_array['is_platform_store'];
                    $goods['is_temlate'] = $common_array['is_temlate'];
                    $goods_id = $goods_model->addGoods($goods);
                    $type_model->addGoodsType($goods_id, $common_id, array(
                        'cate_id' => input('post.cate_id'), 'type_id' => input('post.type_id'), 'attr' => input('post.attr/a')
                    ));
                    $goodsid_array[] = $goods_id;
                }


            }
            $update_goodscommon_data['spec_name'] = is_array(input('post.spec/a')) ? serialize(input('post.sp_name/a')) : serialize(null);
            $update_goodscommon_data['spec_value'] = is_array(input('post.spec/a')) ? serialize(input('post.sp_val/a')) : serialize(null);

        } else {
            # 更新goods表数据里的库存
            $update_goodscommon_data['goods_storage'] = input('param.goods_storage');
            db('goods')->data($update_goodscommon_data)->where(['goods_commonid' => $common_id])->update();
        }


        if (isset($update_goodscommon_data['goods_storage'])) {
            unset($update_goodscommon_data['goods_storage']);
        }
        db('goodscommon')->data($update_goodscommon_data)->where(['goods_commonid' => $common_id])->update();


        $res = db('goodscommon')->data($update_goods_repair_data)->where(['goods_commonid' => $common_id])->update();

        if ($res) {
            // 添加操作日志
            $this->recordSellerlog('商品完善信息，平台货号：' . $common_id);
            return json(['url' => url('Sellergoodsinfomessage/goods_verify_list'), 'code' => 1, 'msg' => '完善成功']);
        } else {
            return json(['url' => url('Sellergoodsinfomessage/goods_verify_list'), 'code' => 0, 'msg' => '完善失败']);
        }


    }


    /**
     * 编辑分类
     */
    public function edit_class()
    {
        // 实例化商品分类模型
        $goodsclass_model = model('goodsclass');
        // 商品分类
        $goods_class = $goodsclass_model->getGoodsclass(session('store_id'));

        // 常用商品分类
        $staple_model = model('goodsclassstaple');
        $param_array = array();
        $param_array['member_id'] = session('member_id');
        $staple_array = $staple_model->getGoodsclassstapleList($param_array);

        $this->assign('staple_array', $staple_array);
        $this->assign('goods_class', $goods_class);

        $this->assign('commonid', input('param.commonid'));
        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('edit_class');
        $this->assign('edit_goods_sign', true);
        return $this->fetch('default/seller/sellergoodsadd/store_goods_add_step1');
    }


    /**
     * 编辑商品页面 第二步
     */
    public function edit_goods()
    {
        $common_id = intval(input('param.commonid'));
        //首先判断该商品是否下架
        $status = db('goodscommon')->where(['goods_commonid' => $common_id])->find();
       if ($common_id <= 0) {
            $this->error(lang('wrong_argument'));
        }

        //商品产地
        $area_model = model('area');
        $where = array();
        $where['area_parent_id'] = 0;
        $top_area_class = $area_model->getarea_list($where, 'area_id,area_name');
        if (empty($top_area_class)) {
            $this->error('暂无省份');
        }
        $this->assign('top_area_class', $top_area_class);


        $http_name = db('config')->where('code', 'qiniu_http')->find();
        $this->assign('http_name', $http_name['value']);

        $goods_model = model('goods');
        $goodscommon_info = $goods_model->getGoodeCommonInfoByID($common_id);
        if (empty($goodscommon_info) || $goodscommon_info['store_id'] != session('store_id') || $goodscommon_info['goods_lock'] == 1) {
            $this->error(lang('goods_not_exist_or_lock'));
        }

        $where = array('goods_commonid' => $common_id, 'store_id' => session('store_id'));
        $goodscommon_info['g_storage'] = $goods_model->getGoodsSum($where, 'goods_storage');
        $goodscommon_info['spec_name'] = unserialize($goodscommon_info['spec_name']);
        if ($goodscommon_info['mobile_body'] != '') {
            $goodscommon_info['mb_body'] = unserialize($goodscommon_info['mobile_body']);
            if (is_array($goodscommon_info['mb_body'])) {
                $mobile_body = '[';
                foreach ($goodscommon_info['mb_body'] as $val) {
                    $mobile_body .= '{"type":"' . $val['type'] . '","value":"' . $val['value'] . '"},';
                }
                $mobile_body = rtrim($mobile_body, ',') . ']';
            }
            $goodscommon_info['mobile_body'] = $mobile_body;
        }
        $aa = db('goods')->where(['goods_commonid' => $common_id])->select();
        if (!isset($aa['1'])) {
            $goodscommon_info['skus'] = $aa['0']['goods_storage'];
        }
        $this->assign('goods', $goodscommon_info);
        $class_id = intval(input('param.class_id'));
        if ($class_id > 0) {
            $goodscommon_info['gc_id'] = $class_id;
        }
        $goods_class = model('goodsclass')->getGoodsclassLineForTag($goodscommon_info['gc_id']);
        $this->assign('goods_class', $goods_class);

        $type_model = model('type');
        // 获取类型相关数据
        $typeinfo = $type_model->getAttribute($goods_class['type_id'], session('store_id'), $goodscommon_info['gc_id']);
        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
        $this->assign('spec_json', $spec_json);
        $this->assign('sign_i', count($spec_list));
        $this->assign('spec_list', $spec_list);
        $this->assign('attr_list', $attr_list);
        $this->assign('brand_list', $brand_list);

        // 取得商品规格的输入值
        $goods_array = $goods_model->getGoodsList($where, 'goods_id,goods_marketprice,goods_price,goods_storage,goods_serial,goods_storage_alarm,goods_spec');

        $sp_value = array();
        if (is_array($goods_array) && !empty($goods_array)) {

            // 取得已选择了哪些商品的属性
            $attr_checked_l = $type_model->typeRelatedList('goodsattrindex', array('goods_id' => intval($goods_array[0]['goods_id'])), 'attrvalue_id');
            $attr_checked = array();
            if (is_array($attr_checked_l) && !empty($attr_checked_l)) {
                foreach ($attr_checked_l as $val) {
                    $attr_checked [] = $val ['attrvalue_id'];
                }
            }
            $this->assign('attr_checked', $attr_checked);

            $spec_checked = array();
            foreach ($goods_array as $k => $v) {
                $a = unserialize($v['goods_spec']);
                if (!empty($a)) {
                    foreach ($a as $key => $val) {
                        $spec_checked[$key]['id'] = $key;
                        $spec_checked[$key]['name'] = $val;
                    }
                    $matchs = array_keys($a);
                    //sort($matchs);
                    $id = str_replace(',', '', implode(',', $matchs));
                    $sp_value ['i_' . $id . '|marketprice'] = $v['goods_marketprice'];
                    $sp_value ['i_' . $id . '|price'] = $v['goods_price'];
                    $sp_value ['i_' . $id . '|id'] = $v['goods_id'];
                    $sp_value ['i_' . $id . '|stock'] = $v['goods_storage'];
                    $sp_value ['i_' . $id . '|alarm'] = $v['goods_storage_alarm'];
                    $sp_value ['i_' . $id . '|sku'] = $v['goods_serial'];
                }
            }
            $this->assign('spec_checked', $spec_checked);
        }
        $this->assign('sp_value', $sp_value);

        // 实例化店铺商品分类模型
        $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
        $this->assign('store_goods_class', $store_goods_class);
        //处理商品所属分类
        $store_goods_class_tmp = array();
        if (!empty($store_goods_class)) {
            foreach ($store_goods_class as $k => $v) {
                $store_goods_class_tmp[$v['storegc_id']] = $v;
                if (isset($v['child'])) {
                    foreach ($v['child'] as $son_k => $son_v) {
                        $store_goods_class_tmp[$son_v['storegc_id']] = $son_v;
                    }
                }
            }
        }
        $goodscommon_info['goods_stcids'] = trim($goodscommon_info['goods_stcids'], ',');
        $goods_stcids = empty($goodscommon_info['goods_stcids']) ? array() : explode(',', $goodscommon_info['goods_stcids']);
        $goods_stcids_tmp = $goods_stcids_new = array();
        if (!empty($goods_stcids)) {
            foreach ($goods_stcids as $k => $v) {
                if (isset($store_goods_class_tmp[$v])) {
                    $storegc_parent_id = $store_goods_class_tmp[$v]['storegc_parent_id'];
                } else {
                    $storegc_parent_id = 0;
                }
                //分类进行分组，构造为array('1'=>array(5,6,8));
                if ($storegc_parent_id > 0) {//如果为二级分类，则分组到父级分类下
                    $goods_stcids_tmp[$storegc_parent_id][] = $v;
                } elseif (empty($goods_stcids_tmp[$v])) {//如果为一级分类而且分组不存在，则建立一个空分组数组
                    $goods_stcids_tmp[$v] = array();
                }
            }
            foreach ($goods_stcids_tmp as $k => $v) {
                if (!empty($v) && count($v) > 0) {
                    $goods_stcids_new = array_merge($goods_stcids_new, $v);
                } else {
                    $goods_stcids_new[] = $k;
                }
            }
        }
        $this->assign('store_class_goods', $goods_stcids_new);

        // 关联版式
        $plate_list = model('storeplate')->getStoreplateList(array('store_id' => session('store_id')), 'storeplate_id,storeplate_name,storeplate_position');
        $plate_list = array_under_reset($plate_list, 'storeplate_position', 2);
        $this->assign('plate_list', $plate_list);
        $this->assign('edit_goods_sign', true);
        $this->assign('edit_type', input('param.type', ''));
        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('edit_goods');
        return $this->fetch('default/seller/sellergoodsadd/store_goods_add_step2');
    }

    /**
     * Notes:保存编辑的商品第二步
     * User: shen
     * Date: 2020/5/9
     * Time: 16:40
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function edit_save_goods()
    {
        $update_data = input('post.');
        if ($update_data['is_spec'] == 2) {
            $update_data['spec'] = '';
        }
        $common_id = intval(input('param.commonid'));
        if (!request()->isPost() || $common_id <= 0) {
            return json(['url' => url('Sellergoodsinfomessage/perfect_goods_list'), 'code' => 0, 'msg' => '操作失败']);
            die;

        }
        if (empty($update_data['spec'])) {
            #如果没有设置规格
            $goods_price = input('post.goods_price', '');
            if (!$goods_price) {
                return json(['url' => '', 'code' => -1, 'msg' => '请设置商品销售价格']);
                die;
            }

            $goods_storage = input('post.goods_storage', '');
            if (!$goods_storage) {
                return json(['url' => '', 'code' => -1, 'msg' => '请设置商品库存']);
                die;
            }

            $goods_storage_alarm = input('post.goods_storage_alarm', '');
            if (!$goods_storage_alarm) {
                return json(['url' => '', 'code' => -1, 'msg' => '请设置商品库存安全值']);
                die;
            }
        }

        $gc_id = intval(input('post.cate_id'));

        // 验证商品分类是否存在且商品分类是否为最后一级
        $data = model('goodsclass')->getGoodsclassForCacheModel();
        if (!isset($data[$gc_id]) || isset($data[$gc_id]['child']) || isset($data[$gc_id]['childchild'])) {

            return json(['url' => '', 'code' => -1, 'msg' => '编辑失败:分类不存在']);
            die;
        }

        // 分类信息
        $goods_class = model('goodsclass')->getGoodsclassLineForTag(intval(input('post.cate_id')));
        $goods_model = model('goods');


        $update_common = array();
        $update_common['goods_name'] = input('post.g_name');
        $update_common['gc_id'] = $gc_id;
        $update_common['gc_id_1'] = isset($goods_class['gc_id_1']) ? intval($goods_class['gc_id_1']) : 0;
        $update_common['gc_id_2'] = isset($goods_class['gc_id_2']) ? intval($goods_class['gc_id_2']) : 0;
        $update_common['gc_id_3'] = isset($goods_class['gc_id_3']) ? intval($goods_class['gc_id_3']) : 0;
        $update_common['gc_name'] = input('post.cate_name');
        $update_common['brand_id'] = input('post.b_id');
        $update_common['brand_name'] = input('post.b_name');

        $update_common['goods_price'] = floatval(input('post.goods_price'));
        $update_common['goods_storage_alarm'] = intval(input('post.goods_storage_alarm'));
        $update_common['goods_body'] = input('post.goods_body');


        #轮播图视频
        if (isset($_POST['videos']) && !empty($_POST['videos'])) {
            $update_common['videos'] = $_POST['videos'];
        } else {
            $update_common['videos'] = '';
        }

        $update_common['spec_name'] = !empty($update_data['spec']) ? serialize(input('post.sp_name/a')) : serialize(null);
        $update_common['spec_value'] = !empty($update_data['spec']) ? serialize(input('post.sp_val/a')) : serialize(null);
        $update_common['goods_vat'] = intval(input('post.g_vat'));

            // 清除原有规格数据
            $type_model = model('type');
            $type_model->delGoodsAttr(array('goods_commonid' => $common_id));

            // 更新商品规格
            $goodsid_array = array();
            $colorid_array = array();
            $spec_array = $update_data['spec'];#获取数组
            if (is_array($spec_array) && !empty($spec_array)) {
                foreach ($spec_array as $k => $value) {
                    if (!isset($value['sp_value'])) {
                        unset($spec_array[$k]);
                    }
                }
                foreach ($spec_array as $value) {
                    $goods_info = db('goods')->where(array('goods_id' => $value['goods_id'], 'goods_commonid' => $common_id, 'store_id' => session('store_id')))->field('goods_id')->find();
                    if (!empty($goods_info)) {
                        $goods_id = $goods_info['goods_id'];
                        $update = array();
                        $update['goods_commonid'] = $common_id;
                        $update['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
                        $update['spec_values'] = implode(',', $value['sp_value']);
                        $update['store_id'] = session('store_id');
                        $update['store_name'] = session('store_name');
                        $update['gc_id'] = $update_common['gc_id'];
                        $update['gc_id_1'] = $update_common['gc_id_1'];
                        $update['gc_id_2'] = $update_common['gc_id_2'];
                        $update['gc_id_3'] = $update_common['gc_id_3'];
                        $update['brand_id'] = $update_common['brand_id'];
                        $update['goods_price'] = $value['price'] == 0 || $value['price'] == '' ? 0 : $value['price'];
                        $update['goods_serial'] = $value['stock'] == '' ? 0 : $value['stock'];
                        $update['goods_storage_alarm'] = intval($value['alarm']) == 0 || intval($value['alarm']) == '' ? 0 : intval($value['alarm']);
                        $update['goods_spec'] = serialize($value['sp_value']);
                        $update['goods_storage'] = $value['stock'] == 0 || $value['stock'] == '' ? 0 : $value['stock'];
                        $update['goods_edittime'] = TIMESTAMP;
                        $goods_model->editGoodsById($update, $goods_id);
                    } else {
                        $insert = array();
                        $insert['goods_commonid'] = $common_id;
                        $insert['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']);
                        $insert['spec_values'] = implode(',', $value['sp_value']);
                        $insert['store_id'] = session('store_id');
                        $insert['store_name'] = session('store_name');
                        $insert['gc_id'] = $update_common['gc_id'];
                        $insert['gc_id_1'] = $update_common['gc_id_1'];
                        $insert['gc_id_2'] = $update_common['gc_id_2'];
                        $insert['gc_id_3'] = $update_common['gc_id_3'];
                        $insert['brand_id'] = $update_common['brand_id'];
                        $insert['goods_price'] = $value['price'];
                        $insert['goods_promotion_price'] = $value['price'];
                        $insert['goods_serial'] = $value['stock'] == '' ? 0 : $value['stock'];
                        $insert['goods_storage_alarm'] = intval($value['alarm']) == 0 || intval($value['alarm']) == '' ? 0 : intval($value['alarm']);
                        $insert['goods_spec'] = serialize($value['sp_value']);
                        $insert['goods_storage'] = $value['stock'] == 0 || $value['stock'] == '' ? 0 : $value['stock'];
                        $insert['goods_addtime'] = TIMESTAMP;
                        $insert['goods_edittime'] = TIMESTAMP;
                        $insert['color_id'] = isset($value['color']) ? intval($value['color']) : '';
                        $goods_id = $goods_model->addGoods($insert);
                    }
                    $goodsid_array[] = intval($goods_id);
                    $colorid_array[] = isset($value['color']) ? intval($value['color']) : '';
                    $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => input('post.cate_id'), 'type_id' => input('post.type_id'), 'attr' => input('post.attr/a')));
                }
            } else {
                $goods_info = $goods_model->getGoodsInfo(array('goods_spec' => serialize(null), 'goods_commonid' => $common_id, 'store_id' => session('store_id')), 'goods_id');
                if (!empty($goods_info)) {
                    $goods_id = $goods_info['goods_id'];
                    $update = array();
                    $update['goods_commonid'] = $common_id;
                    $update['goods_name'] = $update_common['goods_name'];
                    $update['store_id'] = session('store_id');
                    $update['store_name'] = session('store_name');
                    $update['gc_id'] = $update_common['gc_id'];
                    $update['gc_id_1'] = $update_common['gc_id_1'];
                    $update['gc_id_2'] = $update_common['gc_id_2'];
                    $update['gc_id_3'] = $update_common['gc_id_3'];
                    $update['brand_id'] = $update_common['brand_id'];
                    $update['goods_price'] = $update_common['goods_price'];
                    $update['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
                    $update['goods_spec'] = serialize(null);
                    $update['goods_storage'] = intval(input('post.goods_storage'));
                    $update['goods_edittime'] = TIMESTAMP;
                    $goods_model->editGoodsById($update, $goods_id);
                } else {
                    $insert = array();
                    $insert['goods_commonid'] = $common_id;
                    $insert['goods_name'] = $update_common['goods_name'];
                    $insert['store_id'] = session('store_id');
                    $insert['store_name'] = session('store_name');
                    $insert['gc_id'] = $update_common['gc_id'];
                    $insert['gc_id_1'] = $update_common['gc_id_1'];
                    $insert['gc_id_2'] = $update_common['gc_id_2'];
                    $insert['gc_id_3'] = $update_common['gc_id_3'];
                    $insert['brand_id'] = $update_common['brand_id'];
                    $insert['goods_price'] = $update_common['goods_price'];
                    $insert['goods_promotion_price'] = $update_common['goods_price'];
                    $insert['goods_storage'] = intval(input('post.goods_storage'));
                    $insert['goods_storage_alarm'] = $update_common['goods_storage_alarm'];
                    $insert['goods_spec'] = serialize(null);
                    $insert['goods_addtime'] = TIMESTAMP;
                    $insert['goods_edittime'] = TIMESTAMP;
                    $goods_id = $goods_model->addGoods($insert);
                }
                $goodsid_array[] = intval($goods_id);
                $colorid_array[] = 0;
                $type_model->addGoodsType($goods_id, $common_id, array('cate_id' => input('post.cate_id'), 'type_id' => input('post.type_id'), 'attr' => input('post.attr/a')));
            }

            // 清理商品数据
            $goods_model->delGoods(array('goods_id' => array('not in', $goodsid_array), 'goods_commonid' => $common_id, 'store_id' => session('store_id')));
            // 添加操作日志
            $this->recordSellerlog('编辑商品，平台货号：' . $common_id);
             #编辑common表
            $goods_model->editGoodsCommon($update_common, array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
        return json(['url' => url('sellergoodsinfomessage/perfect_goods_list'), 'code' => 1, 'msg' => '编辑成功']);

    }


    /**
     * 第三步完善商品信息
     */
    public function perfect_goods()
    {
        $common_id = input('param.commonid');
        if ($common_id <= 0) {
            $this->error(lang('wrong_argument'), url('Seller/index'));
        }
        /*查询goods商品*/
        $goods_info = db('goods')->where('goods_commonid', $common_id)->select();
        $this->assign('commonid', $common_id);

        $json_goods_info = json_encode($goods_info);
        $this->assign('goods_info', $goods_info);
        $this->assign('json_goods_info', $json_goods_info);

        $top_area = db('area')->where(['area_deep' => 1, 'area_parent_id' => 0])->select();

        foreach ($top_area as $k => $v) {
            $top_area[$k]['area_list'] = db('area')->where(['area_deep' => 2, 'area_parent_id' => $v['area_id']])->field('area_id')->select();
        }
        foreach ($top_area as $k => $v) {
            foreach ($v['area_list'] as $ke => $va) {
                $top_area[$k]['last_id'][] = db('area')->where(['area_deep' => 3, 'area_parent_id' => $va['area_id']])->field('areacode')->select();

            }
        }

        foreach ($top_area as $k => $v) {
            if (!isset($top_area[$k]['last_id'])) {
                $top_area[$k]['last_id'] = array();
            }
        }

        foreach ($top_area as $k => $v) {

            foreach ($v['last_id'] as $ke => $va) {

                foreach ($va as $key => $val) {
                    $top_area[$k]['last_id_info'][] = $val['areacode'];

                }

            }
            unset($top_area[$k]['last_id']);
            unset($top_area[$k]['area_list']);
        }
        foreach ($top_area as $k => $v) {
            if (isset($v['last_id_info'])) {
                $top_area[$k]['last_ids'] = implode(',', $v['last_id_info']);
            } else {
                $top_area[$k]['last_ids'] = $v['areacode'];
            }

        }
        // p($top_area);die;
        $this->assign('top_area', $top_area);

        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('perfect_goods');
        $this->assign('edit_goods_sign', true);
        return $this->fetch('default/seller/sellergoodsadd/perfect_goods');
    }


    /**
     * 编辑图片
     */
    public function edit_image()
    {
        $file_http = db('config')->where('code', 'qiniu_http')->find();
        $this->assign('http_name', $file_http['value']);
        $common_id = intval(input('param.commonid'));
        if ($common_id <= 0) {
            $this->error(lang('wrong_argument'), url('Seller/index'));
        }
        $goods_model = model('goods');
        $common_list = $goods_model->getGoodeCommonInfoByID($common_id);
        if ($common_list['store_id'] != session('store_id') || $common_list['goods_lock'] == 1) {
            $this->error(lang('goods_not_exist_or_lock'), url('Seller/index'));
        }

        $spec_value = unserialize($common_list['spec_value']);
        $this->assign('spec_value', $spec_value);

        $image_list = $goods_model->getGoodsImageList(array('goods_commonid' => $common_id));
        $image_list = array_under_reset($image_list, 'color_id', 2);

        $img_array = $goods_model->getGoodsList(array('goods_commonid' => $common_id), '*', 'color_id');
        // 整理，更具id查询颜色名称
        if (!empty($img_array)) {
            foreach ($img_array as $val) {
                if (isset($image_list[$val['color_id']])) {
                    $image_array[$val['color_id']] = $image_list[$val['color_id']];
                } else {
                    $image_array[$val['color_id']][0]['goodsimage_url'] = isset($val['goodsimage_url']) ? $val['goodsimage_url'] : '';
                    $image_array[$val['color_id']][0]['goodsimage_sort'] = 0;
                    $image_array[$val['color_id']][0]['goodsimage_isdefault'] = 1;
                }
                $colorid_array[] = $val['color_id'];
            }
        }
        $this->assign('img', $image_array);


        $spec_model = model('spec');
        $value_array = $spec_model->getSpecvalueList(array('spvalue_id' => array('in', $colorid_array), 'store_id' => session('store_id')), 'spvalue_id,spvalue_name');
        if (empty($value_array)) {
            $value_array[] = array('spvalue_id' => '0', 'spvalue_name' => lang('no_color'));
        }
        $this->assign('value_array', $value_array);

        $this->assign('commonid', $common_id);

        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('edit_image');
        $this->assign('edit_goods_sign', true);
        return $this->fetch('default/seller/sellergoodsadd/store_goods_add_step3');
    }


    /**
     * 保存商品图片
     */
    public function edit_save_image()
    {


        if (request()->isPost()) {
            #验证是否完善商品信息
            if (input('add_type') == 1) {
                #提交审核
                $common_id = intval(input('param.commonid'));
                $goods_info = db('goods')->where('goods_commonid', $common_id)->find();
                if ($goods_info) {
                    if (!$goods_info['area'] || !$goods_info['is_w_v']) {
                        $data = array();
                        $data['code'] = -1;
                        $data['msg'] = '请先完善商品信息后再提交';
                        return $data;
                    }
                } else {
                    $data = array();
                    $data['url'] = url('sellergoodsinfomessage/goods_verify_list');
                    $data['code'] = -1;
                    $data['msg'] = '操作失败';
                    return $data;
                }
            }


            $common_id = intval(input('param.commonid'));
            $img_array = input('post.img/a');#获取数组
            if ($common_id <= 0 || empty($img_array)) {
                ds_json_encode(10001, lang('wrong_argument'));
            }
            $goods_model = model('goods');
            // 删除原有图片信息
            $goods_model->delGoodsImages(array('goods_commonid' => $common_id, 'store_id' => session('store_id')));
            // 保存
            $insert_array = array();
            foreach ($img_array as $key => $value) {
                $k = 0;
                foreach ($value as $v) {
                    if ($v['name'] == '') {
                        continue;
                    }
                    // 商品默认主图
                    $update_array = array();        // 更新商品主图
                    $update_where = array();
                    $update_array['goods_image'] = $v['name'];
                    $update_where['goods_commonid'] = $common_id;
                    $update_where['store_id'] = session('store_id');
                    $update_where['color_id'] = $key;
                    if ($k == 0 || $v['default'] == 1) {
                        $k++;
                        $update_array['goods_image'] = $v['name'];
                        $update_where['goods_commonid'] = $common_id;
                        $update_where['store_id'] = session('store_id');
                        $update_where['color_id'] = $key;
                        // 更新商品主图
                        if (input('add_type') == 1) {
                            db('goodscommon')->where('goods_commonid', $common_id)->data(['goods_image' => $v['name'], 'goods_status' => '0', 'goods_stateremark' => ''])->update();

                            //修改购物车商品的状态为已关闭
                            $cart_info = db('cart')->where(['goods_commonid' => $common_id])->select();
                            if (!empty($cart_info)) {
                                foreach ($cart_info as $key => $value) {
                                    db('cart')->where(['goods_commonid' => $value['goods_commonid']])->update(['status' => 1]);
                                }
                            }

                        } else {
                            db('goodscommon')->where('goods_commonid', $common_id)->data(['goods_image' => $v['name']])->update();
                        }


                        $goods_model->editGoods($update_array, $update_where);
                    }
                    $tmp_insert = array();
                    $tmp_insert['goods_commonid'] = $common_id;
                    $tmp_insert['store_id'] = session('store_id');
                    $tmp_insert['color_id'] = $key;
                    $tmp_insert['goodsimage_url'] = $v['name'];
                    $tmp_insert['goodsimage_sort'] = ($v['default'] == 1) ? 0 : '';
                    $tmp_insert['goodsimage_isdefault'] = $v['default'];
                    $insert_array[] = $tmp_insert;
                }
            }
            $rs = $goods_model->addGoodsImagesAll($insert_array);
            if (input('add_type') == 1) {
                #提交审核
                if ($rs) {
                    $this->recordSellerlog('编辑商品，平台货号：' . $common_id);
                    $data = array();
                    $data['url'] = url('sellergoodsinfomessage/goods_verify_list');
                    $data['code'] = 1;
                    return $data;
                } else {
                    $data = array();
                    $data['msg'] = '商品图片上传失败,商品已放入草稿箱';
                    $data['url'] = url('sellergoodsinfomessage/perfect_goods_list');
                    $data['code'] = 0;
                    return $data;
                }
            } else {
                #暂存
                if ($rs) {
                    $this->recordSellerlog('编辑商品，平台货号：' . $common_id);
                    $data = array();
                    $data['url'] = url('sellergoodsinfomessage/perfect_goods_list');
                    $data['code'] = 1;
                    return $data;
                } else {
                    $data = array();
                    $data['msg'] = '商品图片上传失败,商品已放入草稿箱';
                    $data['url'] = url('sellergoodsinfomessage/perfect_goods_list');
                    $data['code'] = 0;
                    return $data;

                }
            }

        }
    }


    /**
     * 删除待审核商品
     * */
    public function drop_goods()
    {
        $goods_model = new Goods();
        $commonid = input('param.commonid');
        $common_id = $this->checkRequestCommonId($commonid);
        $commonid_array = explode(',', $common_id);
        $where = array();
        $where['goods_commonid'] = array('in', $commonid_array);
        $return = $goods_model->delGoodsNoLock($where);

        if ($return) {
            // 添加操作日志
            $this->recordSellerlog('删除商品，平台货号：' . $common_id);
            ds_json_encode(10000, '删除成功');
        } else {
            ds_json_encode(10001, '删除失败');
        }
    }

    /**草稿箱列表
     */
    public function perfect_goods_list()
    {

        $goods_model = new Goods();
        $where = array();
        $where['store_id'] = session('store_id');
        $where['goods_status'] = -1;


        $b_id = intval(input('get.b_id'));
        if ($b_id != '') {
            $where['brand_id'] = intval($b_id);
        }
        $gc_id = intval(input('get.gc_id'));
        if ($gc_id != '') {
            $where["gc_id|gc_id_1|gc_id_2|gc_id_3"] = $gc_id;
        }
        $keyword = trim(input('get.keyword'));
        $search_type = trim(input('get.search_type'));
        if (trim($keyword) != '') {
            switch ($search_type) {
                case 1:
                    $where['goods_name'] = array('like', '%' . trim($keyword) . '%');
                    break;
                case 2:
                    $where['goods_commonid'] = intval($keyword);
                    break;
            }
        }

        $goods_list = $goods_model->g_getGoodsCommonList($where);
        $this->assign('show_page', $goods_model->page_info->render());
        $this->assign('goods_list', $goods_list);
        // 计算库存
        $storage_array = $goods_model->calculateStorage($goods_list);
        $this->assign('storage_array', $storage_array);

        // 商品分类
        $store_goods_class = model('storegoodsclass')->getClassTree(array('store_id' => session('store_id'), 'storegc_state' => '1'));
        $this->assign('store_goods_class', $store_goods_class);
        //分类
        $goods_class = model('goodsclass')->getGoodsclassLineForTag('91');
        $this->assign('goods_class', $goods_class);

        $goodsclass_model = model('goodsclass');
        //父类列表，只取到第二级
        $parent_list = $goodsclass_model->getTreeClassList(2);
        $gc_list = array();
        if (is_array($parent_list)) {
            foreach ($parent_list as $k => $v) {
                $parent_list[$k]['gc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['gc_name'];
                if ($v['deep'] == 1)
                    $gc_list[$k] = $v;
            }
        }
        $this->assign('gc_list', $gc_list);

        //品牌
        $typeinfo = model('type')->getAttribute('1', session('store_id'), '91');
        list($spec_json, $spec_list, $attr_list, $brand_list) = $typeinfo;
        //  p($brand_list);die;
        $this->assign('brand_list', $brand_list);
        $this->setSellerCurMenu('sellergoodsinfomessage');
        $this->setSellerCurItem('perfect_goods_list');
        return $this->fetch($this->template_dir . 'perfect_goods_list');
    }


    /** 审核通过商品删除
     */
    public function drop_goods_lock()
    {

        $commonid = input('param.commonid');

        $common_info = db('goodscommon')->where('store_id', session('store_id'))->where('goods_commonid', $commonid)->find();
        if (empty($common_info)) {
            ds_json_encode(10001, '您的商品库里没有存在此商品');
        }
        $return = db('goodscommon')->where('store_id', session('store_id'))->where('goods_commonid', $commonid)->data(['goods_lock' => 1])->update();
        //修改运营商 y_goods表的商品状态
        db('y_goods')->where(['goods_commonid' => $commonid])->update(['is_del' => 1]);


        //修改购物车商品的状态为已关闭
        $cart_info = db('cart')->where(['goods_commonid' => $commonid])->select();
        if (!empty($cart_info)) {
            foreach ($cart_info as $key => $value) {
                db('cart')->where(['goods_commonid' => $value['goods_commonid']])->update(['status' => 1]);
            }
        }


        if ($return) {
            // 添加操作日志
            $this->recordSellerlog('删除商品，平台货号：' . $commonid);
            ds_json_encode(10000, '删除成功');
        } else {
            ds_json_encode(10001, '删除失败');
        }
    }

    /** 上下架
     */
    public function goods_status()
    {

        $commonid = input('param.commonid');

        $common_info = db('goodscommon')->where('store_id', session('store_id'))->where('goods_commonid', $commonid)->find();
        if (empty($common_info)) {
            ds_json_encode(10001, '您的商品库里没有存在此商品');
        }

        //找到goods
        $goods_info = db('goods')->where(['goods_commonid' => $commonid])->find();

        if ($common_info['goods_status'] == 3) {
            //上架
            //判断商品的销售区域是否设置  如果未设置的话默认全部地区
            // if(empty($goods_info['area'])){
            //     //找到全部区域的
            //     $way_info = db('waybill')->where(['area_type'=>0])->find();
            //     $info = json_decode($way_info['area_content']);
            //     $update_info['area'] = $info['area_id'];
            //     $update_info['area_name'] = $info['area_name'];
            //     db('goods')->where(['goods_commonid'=>$commonid])->update($update_info);
            // }

            $data['goods_status'] = 1;
        } elseif ($common_info['goods_status'] == 1) {
            //供应商操作下架   运营y_goods表里的商品也要下架
            $tag = db('y_goods')->where(['goods_commonid' => $commonid])->select();
            if (!empty($tag)) {
                foreach ($tag as $key => $value) {
                    db('y_goods')->where(['goods_commonid' => $commonid])->update(['status' => 1]);
                }
            }
            $data['goods_status'] = 3;
        }
        $return = db('goodscommon')->where('store_id', session('store_id'))->where('goods_commonid', $commonid)->data($data)->update();
        if ($return) {
            // 添加操作日志
            $this->recordSellerlog('商品下架，平台货号：' . $commonid);
            ds_json_encode(10000, '操作成功');
        } else {
            ds_json_encode(10001, '操作失败');
        }
    }


    /**
     * 验证commonid
     */
    private function checkRequestCommonId($common_ids)
    {
        if (!preg_match('/^[\d,]+$/i', $common_ids)) {
            ds_json_encode(10001, lang('param_error'));
        }
        return $common_ids;
    }

    /**
     * AJAX获取商品分类
     */
    public function ajax_class()
    {
        $id = intval(input('param.id'));
        $deep = intval(input('param.deep'));
        if ($id <= 0 || $deep <= 0 || $deep >= 4) {
            echo 'false';
            exit();
        }
        $deep += 1;
        $goodsclass_model = model('goodsclass');

        // 验证分类是否存在
        $gc_info = $goodsclass_model->getGoodsclassInfoByIds($id);
        if (empty($gc_info)) {
            echo 'false';
            exit();
        }

        // 读取商品分类
        if ($deep != 4) {
            $gc_list = $goodsclass_model->getGoodsclass($this->_store_id, $id, $deep);
        }
        // 分类不为空输出分类信息
        if (!empty($gc_list)) {
            $data = array('type' => 'class', 'data' => $gc_list, 'deep' => $deep);
        } else {
            // 查询类型
            $type_model = model('type');
            $spec_list = $type_model->getSpecByType(array('type_id' => $gc_info['type_id']), 't.type_id, s.*');

            $data = array('type' => 'spec', 'data' => $spec_list, 'gcid' => $id, 'aa' => $gc_info, 'gcid' => $id, 'deep' => $deep);
        }

        echo json_encode($data);
        exit();
    }

    /**
     *    栏目菜单
     */
    function getSellerItemList()
    {
        if (request()->action() === 'edit_goods' || request()->action() === 'edit_image' || request()->action() === 'perfect_goods' || request()->action() === 'edit_class') {
            $item_list[] = array(
                'name' => 'edit_class',
                'text' => '编辑分类信息',
                'url' => url('Sellergoodsinfomessage/edit_class', ['commonid' => input('param.commonid')]),
            );
            $item_list[] = array(
                'name' => 'edit_goods',
                'text' => '编辑基本信息',
                'url' => url('Sellergoodsinfomessage/edit_goods', ['commonid' => input('param.commonid')]),
            );
            $item_list[] = array(
                'name' => 'perfect_goods',
                'text' => '完善商品信息',
                'url' => url('Sellergoodsinfomessage/perfect_goods', ['commonid' => input('param.commonid')]),
            );
            $item_list[] = array(
                'name' => 'edit_image',
                'text' => lang('edit_image'),
                'url' => url('Sellergoodsinfomessage/edit_image', ['commonid' => input('param.commonid')]),
            );
        } else {
            $item_list = array(
                array(
                    'name' => 'goods_list',
                    'text' => '在售商品',
                    'url' => url('Sellergoodsinfomessage/index'),
                ),
                array(
                    'name' => 'goods_off_list',
                    'text' => '未通过审核商品',
                    'url' => url('Sellergoodsinfomessage/goods_off_list')),
                array(
                    'name' => 'goods_verify_list',
                    'text' => '待审核商品',
                    'url' => url('Sellergoodsinfomessage/goods_verify_list')),
                array(
                    'name' => 'perfect_goods_list',
                    'text' => '商品草稿箱',
                    'url' => url('Sellergoodsinfomessage/perfect_goods_list')),
            );
        }


        return $item_list;
    }

}